/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: GammuStateMachineCLTest.java 656 2007-06-27 09:32:35Z jack.rybicki $
 */
package gammu.java.machines;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import gammu.java.GSMErrorException;
import gammu.java.GammuStateMachine;
import gammu.java.OutgoingSMS;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * Test for {@link gammu.java.machines.GammuStateMachineCL}.
 * 
 */
public class GammuStateMachineCLTest {

	private GammuStateMachineCL sm;

	/**
	 * DOCUMENT ME!
	 * 
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		sm = new GammuStateMachineCL();
	}

	/**
	 * DOCUMENT ME!
	 * 
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#answerCall()}.
	 */
	@Test(timeout = 6000)
	public void testAnswerCall() {
		sm.cancelCall();
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#cancelCall()}.
	 */
	@Test(timeout = 6000)
	public void testCancelCall() {
		sm.dialVoice("*550", GammuStateMachine.ShowNumber.DEFAULT);
		sm.cancelCall();
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#dialVoice(java.lang.String, boolean)}.
	 */
	@Test(timeout = 6000)
	public void testDialVoice() {
		sm.dialVoice("*550", GammuStateMachine.ShowNumber.DEFAULT);
		sm.cancelCall();
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#getBatteryInfo()}.
	 */
	@Test(timeout = 6000)
	public void testGetBatteryInfo() {
		Map<String, String> m = sm.getBatteryInfo();
		assertNotNull(m);
		for (String k : m.keySet()) {
			System.out.println(k + ":" + m.get(k));
			assertNotNull(k);
			assertNotNull(m.get(k));
		}
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#getAllNetworks()}.
	 */
	@Test(timeout = 6000)
	public void testGetAllNetworks() {
		List<String> l = sm.getAllNetworks();
		assertNotNull(l);
		for (String s : l) {
			System.out.println(s);
		}
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#getNetworkInfo()}.
	 */
	@Test(timeout = 6000)
	public void testGetNetworkInfo() {
		Map<String, String> m = sm.getNetworkInfo();
		assertNotNull(m);
		for (String k : m.keySet()) {
			System.out.println(k + ":" + m.get(k));
			assertNotNull(k);
			assertNotNull(m.get(k));
		}
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#getPhoneId()}.
	 */
	@Test(timeout = 6000)
	public void testGetPhoneId() {
		Map<String, String> m = sm.getPhoneId();
		assertNotNull(m);
		assertTrue(m.keySet().size() > 0);
		for (String k : m.keySet()) {
			System.out.println(k + ":" + m.get(k));
			assertNotNull(k);
			assertNotNull(m.get(k));
		}
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#getSMS(java.lang.String, int)}.
	 */
	@Test(timeout = 6000)
	public void testGetSMS() {
		// fail("Not yet implemented");
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#getSMSC(int)}.
	 */
	@Test(timeout = 6000)
	public void testGetSMSC_1() {
		try {
			sm.getSMSC(0);
			fail();
		} catch (GSMErrorException e) {
			assertEquals(GSMErrorException.ERR_INVALIDSMSCID, e);
		}
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#getSMSC(int)}.
	 */
	@Test(timeout = 6000)
	public void testGetSMSC_2() {
		Map<String, String> m = sm.getSMSC(1);
		assertNotNull(m);
		for (String k : m.keySet()) {
			System.out.println(k + ":" + m.get(k));
			assertNotNull(k);
			assertNotNull(m.get(k));
		}
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#getSMSC(int)}.
	 */
	@Test(timeout = 6000)
	public void testGetSMSC_3() {
		try {
			sm.getSMSC(99);
			fail();
		} catch (GSMErrorException e) {
			assertEquals(GSMErrorException.ERR_INVALIDSMSCID, e);
		}
	}

	/**
	 * Test method for {@link gammu.java.machines.GammuStateMachineCL#init()}.
	 */
	@Test(timeout = 6000)
	public void testInit() {
		sm.init();
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#pressKey(char, boolean)}.
	 */
	@Test(timeout = 6000)
	public void testPressKey_1() {
		sm.pressKey('1', true);
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#pressKey(char, boolean)}.
	 */
	@Test(timeout = 6000)
	public void testPressKey_2() {
		try {
			sm.pressKey('s', true);
		} catch (GSMErrorException e) {
			assertEquals(e, GSMErrorException.ERR_NOTSUPPORTEDPARAMETER);
		}
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#pressKey(char, boolean)}.
	 */
	@Test
	public void testPressKey_3() {
		sm.pressKey('5', true);
		sm.pressKey('0', true);
		sm.pressKey('5', true);
		sm.pressKey('0', true);
		sm.pressKey('3', true);
		sm.pressKey('4', true);
		sm.pressKey('9', true);
		sm.pressKey('8', true);
		sm.pressKey('7', true);
		sm.pressKey('#', true);
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#pressKeySequence(String)}.
	 */
	@Test(timeout = 10000)
	public void testPressKeySequence() {
		sm.pressKeySequence("505034987#");
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#readConfig(int)}.
	 */
	@Test(timeout = 6000)
	public void testReadConfig_1() {
		sm.readConfig(1);
		try {
			sm.getPhoneId();
			fail();
		} catch (GSMErrorException e) {

		}
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#readConfig(int)}.
	 */
	@Test(timeout = 6000)
	public void testReadConfig_2() {
		sm.readConfig(3);
		Map<String, String> m = sm.getPhoneId();
		assertNotNull(m);
		assertTrue(m.keySet().size() > 0);
		for (String k : m.keySet()) {
			System.out.println(k + ":" + m.get(k));
			assertNotNull(k);
			assertNotNull(m.get(k));
		}
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#sendSMS(OutgoingSMS)}.
	 */
	@Test(timeout = 6000)
	public void testSendSMS_1() {
		sm.sendSMS(new OutgoingSMS("505034987", "test123"));
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#sendSMS(OutgoingSMS)}.
	 */
	@Test(timeout = 6000)
	public void testSendSMS_2() {
		sm.sendSMS(new OutgoingSMS("550", "505034987"));
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#setConfig(java.util.Map)}.
	 */
	@Test(timeout = 6000)
	public void testSetConfig() {
		fail("Not yet implemented");
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#setIncomingCall(boolean)}.
	 */
	@Test
	public void testSetIncomingCall() {
		sm.setIncomingCall(true);
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#addIncomingCallback(gammu.java.GammuObserver)}.
	 */
	@Test(timeout = 6000)
	public void testSetIncomingCallback() {
		// fail("Not yet implemented");
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#setIncmingCB(boolean)}.
	 */
	@Test(timeout = 6000)
	public void testSetIncmingCB() {
		// fail("Not yet implemented");
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#setIncomingSMS(boolean)}.
	 */
	@Test(timeout = 6000)
	public void testSetIncomingSMS() {
		// fail("Not yet implemented");
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#setIncomingUSSD(boolean)}.
	 */
	@Test(timeout = 6000)
	public void testSetIncomingUSSD() {
		// fail("Not yet implemented");
	}

	/**
	 * Test method for
	 * {@link gammu.java.machines.GammuStateMachineCL#terminate()}.
	 */
	@Test(timeout = 6000)
	public void testTerminate() {
		// nothing to be tested
	}

}
